package pri.lt.client;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import pri.lt.Constants;
import pri.lt.bean.BBSResponse;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class LabelClient {

    public static String getLabelIdByName(String name) {

        RestTemplate restTemplate = new RestTemplate();

        Map<String, String> params2= new HashMap<>();
        params2.put("name", name);



        ResponseEntity<BBSResponse> result = restTemplate.getForEntity(Constants.BBS_LABEL_URL + "?name={name}", BBSResponse.class, params2);
        System.out.println("getLabelIdByName result: " + result.getStatusCode());

        String labelId = result.getBody().getData();
        if (labelId != null && labelId.trim().length() > 0) {
            return labelId;
        }
        return null;
    }

    public static String getRandomLabel() {

        RestTemplate restTemplate = new RestTemplate();

        Map<String, String> params2= new HashMap<>();



        ResponseEntity<BBSResponse> result = restTemplate.getForEntity(Constants.BBS_LABEL_RANDOM, BBSResponse.class, params2);
        System.out.println("getLabelIdByName result: " + result.getStatusCode());

        String labelId = result.getBody().getData();
        if (labelId != null && labelId.trim().length() > 0) {
            return labelId;
        }
        return null;
    }
}
